package org.soenea.doitall.domain.model.group.data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.dsrg.soenea.service.threadLocal.DbRegistry;

public class GroupFinder {
	
	public static String SELECT_BY_ID_SQL = "SELECT g.groupId,g.version,g.groupName,g.description FROM " + GroupTDG.TABLE + " AS g "+
			   "WHERE g.groupId=?;";

	public static String SELECT_ALL_SQL = "SELECT g.groupId,g.version,g.groupName,g.description FROM " + GroupTDG.TABLE + " AS g;";
			  
	public static String SELECT_BY_NAME_SQL = "SELECT g.groupId,g.version,g.groupName, g.description FROM " + GroupTDG.TABLE + " AS g "+
			   "WHERE g.groupName=?;";
			  
	public static ResultSet findAll() throws SQLException {
		PreparedStatement ps = DbRegistry.getDbConnection().prepareStatement(SELECT_ALL_SQL);
		return ps.executeQuery();
	}
	
	public static ResultSet find(long id) throws SQLException {
		PreparedStatement ps = DbRegistry.getDbConnection().prepareStatement(SELECT_BY_ID_SQL);
		ps.setLong(1, id);
		return ps.executeQuery();
	}
	public static ResultSet findByName(String name) throws SQLException{
		PreparedStatement ps = DbRegistry.getDbConnection().prepareStatement(SELECT_BY_NAME_SQL);
		ps.setString(1, name);
		return ps.executeQuery();
	}

}
